import { Dict } from "./dict"

export const customDictList = function(dictObj){
  const keys = Object.keys(dictObj)
  let array = []
  for(var i=0;i<keys.length;i++){
    array.push(dictObj[keys[i]])
  }
  return array
}

const TraceEventType = {BtnAddPost: { name: '点击准备发布按钮', value: 2601, childs:{} },
BtnAddComment: { name: '点击留言', value: 2602, childs:{} },
BtnAddContact: { name: '点击联系方式', value: 2603, childs:{} },
BtnAddPurchaseMember: { name: '点击购买会员', value: 2604, childs:{} },
}


const PostStatusEnum = {Init: { name: '待审核', value: 0, childs:{} },
Agree: { name: '审核通过', value: 1, childs:{} },
Finish: { name: '交易完成', value: 3, childs:{} },
Refuse: { name: '审核拒绝', value: 2, childs:{} },
Close: { name: '发帖关闭', value: 4, childs:{} },}

const TradeStateEnum = {SUCCESS: { name: '支付成功', value: 'SUCCESS', childs:{} },
REFUND: { name: '转入退款', value: 'REFUND', childs:{} },
NOTPAY: { name: '未支付', value: 'NOTPAY', childs:{} },
CLOSED: { name: '已关闭', value: 'CLOSED', childs:{} },
REVOKED: { name: '已撤销（付款码支付）', value: 'REVOKED', childs:{} },
USERPAYING: { name: '用户支付中（付款码支付）', value: 'USERPAYING', childs:{} },
PAYERROR: { name: '支付失败(其他原因，如银行返回失败)', value: 'PAYERROR', childs:{} },}

const ConstantVals = {
	// 非会员每日最多发起的聊天次数和打电话次数
	NonMember: {
		CountOfChat: 4,
		CountOfContact: 4,
		TipOfChat: '非会员每日最多发起3次聊天，您今日聊天次数已用完哦～',
		TipOfChatFun: (count) => {
			return '非会员每日最多发起3次聊天，您今日已发起'+count+'次'
		},
		TipOfContact: '非会员每日最多拨打3次电话，您今日可拨打次数已用完哦～',
		TipOfContactFun: (count) => {
			return '非会员每日最多拨打3次电话，您今日已拨打'+count+'次'
		}
	}
}


export const acreageList = [
  // acreage 不限、20平以下、20-50平、10-100平、100-200平、200-500平及自定义面积
  {
    name: '不限',
    value: '0-10000'
  },
  {
    name: '20平以下',
    value: '0-20'
  },
  {
    name: '20-50平',
    value: '20-50'
  },
  {
    name: '50-100平',
    value: '50-100'
  },
  {
    name: '100-200平',
    value: '100-200'
  },
  {
    name: '200-500平',
    value: '200-500'
  },
  {
    name: '500平以上',
    value: '500-10000'
  },
]

export const getAcreageDesc = function(lowerAcreage, upperAcreage){
  if(upperAcreage >= 10000){
    if(lowerAcreage > 0){
      return lowerAcreage + '平以上'
    }else{
      return '不限'
    }
  }else if(lowerAcreage <= 0){
    return upperAcreage + '平以下'
  }else{
    return lowerAcreage + '-' + upperAcreage + '平'
  }
}

export const getAcreageDict = function(lowerAcreage, upperAcreage){
  let value = lowerAcreage + '' + upperAcreage
  acreageList.forEach(acreage => {
    if(acreage.value == value){
      return acreage
    }
  })
  return {value: 0, name: ''}
}

export const rentList = [
  // 不限、2千以下、2000-5000、5000-10000、1万-2万、2万-5万、5万以上
  {
    name: '不限',
    value: '0-1000000'
  },
  {
    name: '2千以下',
    value: '0-2000'
  },
  {
    name: '2000-5000',
    value: '2000-5000'
  },
  {
    name: '5000-10000',
    value: '5000-10000'
  },
  {
    name: '1万-2万',
    value: '10000-20000'
  },
  {
    name: '2万-5万',
    value: '20000-50000'
  },
  {
    name: '5万以上',
    value: '50000-1000000'
  },
]
export const getRentDesc = function(lowerRent, upperRent){
  if(upperRent >= 1000000){
    if(lowerRent > 0){
      return lowerRent / 10000 + '万以上'
    }else{
      return '不限'
    }
  }else if(lowerRent >= 10000){
    return lowerRent / 10000 + '万-' + upperRent / 10000 + '万'
  }else if(lowerRent >= 1000){
    return lowerRent / 1000 + 'k-' + upperRent / 1000 + 'k'
  }else if(lowerRent == 0){
    return upperRent / 1000 + 'k以下'
  }else{
    return lowerRent + '元-' + upperRent + '元'
  }
}
export const getSimpleRent = function(rent){
  if(rent > 10000){
    return parseFloat((rent / 10000).toFixed(1)) + '万'
    
  }else if(rent > 1000){
    return parseFloat((rent / 1000).toFixed(1)) + '千'
  }else{
    return rent + '元'
  }
}

export const getSimpleRentValue = function(rent){
  if(rent > 10000){
    return parseFloat((rent / 10000).toFixed(1))
    
  }else if(rent > 1000){
    return parseFloat((rent / 1000).toFixed(1))
  }else{
    return rent
  }
}

export const getSimpleRentUnit = function(rent){
  if(rent > 10000){
    return '万'
    
  }else if(rent > 1000){
    return '千'
  }else{
    return '元'
  }
}
export const shopTypeList = [
  {
    value: 0,
    name: '店铺'
  },
  {
    value: 1,
    name: '空铺'
  },
]

export const parseFieldDictList = function(fieldName){
  if(fieldName == 'industryId'){
    return customDictList(Dict.IndustryTypeEnum)
  }else if(fieldName == 'shopType'){
    return shopTypeList
  }
}

export const parseFieldIndex = function(postDto, fieldName, dictList){
  for(var i=0;i<dictList.length;i++){
    if(postDto[fieldName] == dictList[i].value){
      return i
    }
  }
  return 0
}

export const getDictName = function(dictValue,dictObj){
  let dictAry = customDictList(dictObj)
  for(var i=0;i<dictAry.length;i++){
    if(dictAry[i].value == dictValue){
      return dictAry[i].name
    }
  }
}
export const getShopLabelList = function(){
  let labelList = customDictList(Dict.ShopLabelEnum)
  let result = []
  for(var i=0;i<labelList.length;i++){
    result.push({
      labelId: labelList[i].value,
      labelName: labelList[i].name,
    })
  }
  console.log('所有店铺标签列表', result)
  return result
}

export const CustomDict = {
  acreageList,
  shopTypeList,
  rentList,
  getRentDesc,
  customDictList,
  parseFieldIndex,
  parseFieldDictList,
  getDictName,
  PostStatusEnum,
  getShopLabelList,
  getAcreageDict,
  getAcreageDesc,
  getSimpleRent,
  getSimpleRentValue,
  getSimpleRentUnit,
  TraceEventType,
  TradeStateEnum,
  ConstantVals
}